#!/usr/bin/env python
# -*- coding: UTF-8 -*-

try:
	import pygame
	import sys
	import utils
	from pygame.locals import *
except ImportError, err:
	print "Could not load %s module." % (err)
	sys.exit(2)


def get_cursor_tile():
	return utils.get_cursor_icons().subsurface(((0, 32 * CURSOR), (32, 32)))

# "constants"
MELEE_ATK = 0
RANGED_ATK = 1
MOVE = 2
NA = 3
DEF_MAGIC = 4
CURSOR = 5
ATK_MAGIC = 6
BLANK = 7

'''
Emblem

This is the small animated icon that appears in the middle of the
cursor when the user is about to execute a game action (move, attack,
magic, etc.).
'''

class Emblem(pygame.sprite.Sprite):
	def __init__(self):
		pygame.sprite.Sprite.__init__(self)
		self.frame = 0
		self.mov_seq = 0
		self.action = BLANK
		self.rect = pygame.rect.Rect((0, 0, 32, 32))
		self.image = pygame.surface.Surface(self.rect.size).convert()
		self.image.set_colorkey(utils.get_cursor_icons().get_at((0,0)), RLEACCEL)

	def set_action(self, action = None):
		if action is None:
			self.action = BLANK
			self.image.fill(self.image.get_colorkey())
			return

		self.action = action
		self.mov_seq = 0
		self.frame = 0
		self.image.blit(utils.get_cursor_icons().subsurface(((0, 32 * self.action), (32, 32))), (0,0))

	def update(self):
		self.frame = (self.frame + 1) % 20
		if self.action != BLANK and self.frame == 0:
			self.mov_seq  = (self.mov_seq + 1) % 2
			self.image.blit(utils.get_cursor_icons().subsurface(((32 * self.mov_seq, 32 * self.action), (32, 32))), (0,0))
			return 1
		return 0
